﻿-- =============================================
-- Create Objects required for Partitioning
-- =============================================
IF SERVERPROPERTY('EngineEdition') = 3
	PRINT 'Creating Missing Partition Functions.'
GO
--First create all Partition Functions

IF SERVERPROPERTY('EngineEdition') = 3
BEGIN 
	IF NOT EXISTS(SELECT 1 FROM sys.partition_functions where name ='PF_DateRange_Year')
	BEGIN 
		PRINT 'Creating PF_DateRange_Year...'
		:r "..\..\..\Schema Objects\Storage\Partition Functions\PF_DateRange_Year.partitionfunction.sql"
	END
END
GO
IF SERVERPROPERTY('EngineEdition') = 3
	PRINT 'Creating Missing Partition Schemes.'
GO
IF SERVERPROPERTY('EngineEdition') = 3
BEGIN 
	--NOW do the Partition Schemes
	IF NOT EXISTS(SELECT 1 FROM sys.partition_schemes where name = 'PScheme_Audit')
	BEGIN
		PRINT 'Creating Pscheme_Audit...'
		:r "..\..\..\Schema Objects\Storage\Partition Schemes\PScheme_Audit.partitionscheme.sql"
	END
END 